package com.six.JacksonOperation;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.six.entity.Order;
import com.six.entity.Person;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * ClassName:JsonToJava
 * Package:com.six
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/27 - 22:48
 * @Version:v1.0
 */
//Jackson 日期格式化
public class JsonToJava9 {

    public static void main(String[] args) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
        Order order = new Order();
        order.setId(1);
        order.setDate(new Date());
        order.setLocalDateTime(LocalDateTime.now());
        //将java转换成json字符串
        String json = objectMapper.writeValueAsString(order);
        //{"id":1,"date":"2023年07月28日 15时14分01秒","localDateTime":"2023-07-28 15:14:01"}
        System.out.println(json);
        //将json字符串转换成java对象
        Order orderObject = objectMapper.readValue(json, Order.class);
        //Order(id=1, date=Fri Jul 28 15:15:59 CST 2023, localDateTime=2023-07-28T15:15:59)
        System.out.println(orderObject);
    }
}
